package com.abu.server.utils;

import lombok.Data;

import java.util.HashMap;


@Data
public class Resp {

    private Boolean success;

    private Integer code;

    private String msg;

    private HashMap<String, Object> data = new HashMap<>();

    private Resp() {
    }

    public static Resp ok() {
        Resp r = new Resp();
        r.setCode(20000);
        r.setMsg("成功");
        r.setSuccess(true);
        return r;
    }

    public static Resp error() {
        Resp r = new Resp();
        r.setCode(20001);
        r.setMsg("失败");
        r.setSuccess(false);
        return r;
    }

    public Resp success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public Resp code(Integer code) {
        this.setCode(code);
        return this;
    }

    public Resp msg(String msg) {
        this.setMsg(msg);
        return this;
    }

    public Resp data(HashMap<String, Object> data) {
        this.setData(data);
        return this;
    }

    public Resp data(String s1, Object data) {
        this.data.put(s1, data);
        return this;
    }

}
